<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" :rows="3" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      height="500px"
      selectionType="single"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="onRowSelectChange"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取消</el-button>
      <el-button type="primary" @click="confirmClick">确定</el-button>
    </div>
    <BaseDialog :visible.sync="actions.visible" :title="actions.title" destroyOnClose width="70%">
      <addRescuePanel :type.sync="actions.type" :formData="this.resData" @close="actions.visible = false"/>
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getOwnerInf,getRescueNo } from '@/api/repair/repairBusiness/rescueService/index';
import addRescuePanel from '@/pages/customerRepair/rescueManagement/rescueOrder/addRescuePanel';
import { getRescueList} from '@/api/customerRepair/rescueManagement/rescueOrder';

export default {
  name: 'queryRescueNoPanel',
  components: {addRescuePanel},
  mixins: [dictionary],
  props: {
    row: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    this.BaseTable = null;
    this.selectData = [];
    this.resData = {};
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: { xhrAbort: false },
      fetchApi: getRescueList,
      columns: this.createTableColumns(),
      actions: { type: 'detail', title: '救援单明细', visible: false }
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
          {
          type: 'INPUT',
          label: '救援单编号',
          fieldName: 'rescueNo',
          placeholder: '请输入救援单编号...'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          placeholder: '请输入车牌号...'
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入vin...'
        },
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'ownerName',
          placeholder: '请输入车主姓名...'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: props => {
            return (
              <div>           
                <el-button size="mini" type="text" onClick={() => this.openHandler(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '救援单编号',
          dataIndex: 'rescueNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'license',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'model',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发动机号/电机号',
          dataIndex: 'engineNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '当前里程数',
          dataIndex: 'mileage',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '保修开始日期',
          dataIndex: 'guaranteeBegDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd HH:mm:ss'
        },
        {
          title: '车主姓名',
          dataIndex: 'ownerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车主电话',
          dataIndex: 'ownerMobile',
          sorter: true,
          filter: true,
          filterType: 'input'
        }

      ];
    },
    onRowSelectChange(val) {
      this.selectData = val;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeDialog() {
      this.$emit('close', false);
    },
    confirmClick() {
      this.$emit('save', this.selectData);
      // this.$emit('close', false);
    },
    openHandler(row) {
      this.resData = row;
      this.actions.visible = true;
      this.actions.type = 'detail';

    }
  }
};
</script>

<style lang="less" scoped></style>
